<%@page import="net.zoneland.cas.*"%>
<%!
private String getConfig(javax.servlet.ServletContext  application, String key){
   // String serverName=application.getInitParameter("serverName");
    String v =  CasAppHelper.getProperty("cas."+key,null);
    return v == null ? application.getInitParameter(key) : v;
}
%>
<%
session.invalidate();
String logoutSuccessRedirectUrl = (String) application.getAttribute("logoutSuccessRedirectUrl");
if(logoutSuccessRedirectUrl == null){
    String serverName=getConfig(application,"serverName");
	String reqUrl = request.getRequestURL().toString();
	int idx=reqUrl.indexOf('/', 9);
	if ( idx != -1 ){
	    serverName=reqUrl.substring(0,idx);
	}
	logoutSuccessRedirectUrl=serverName+request.getContextPath();
	//logoutSuccessRedirectUrl = CustomAssertionUtils.constructServiceUrl(request, response);
	if(logoutSuccessRedirectUrl.charAt(logoutSuccessRedirectUrl.length()-1) != '/'){
	    logoutSuccessRedirectUrl += "/";
	}	
}
String logoutUrl = CustomAssertionUtils.constructLogoutUrl(logoutSuccessRedirectUrl);
if (logoutUrl == null){
    logoutUrl = getConfig(application,"casServerLoginUrl");
    if (logoutUrl != null &&logoutUrl.endsWith("/login")){
        logoutUrl = logoutUrl.substring(0,logoutUrl.length()-5);
    }
	if(logoutUrl.charAt(logoutUrl.length()-1) != '/'){
	    logoutUrl +='/';
	}
	logoutUrl += "logout";
}
logoutUrl += "?service=" +logoutSuccessRedirectUrl;
response.sendRedirect(logoutUrl);
%>